﻿using BD.Standard.YCWH.ProgramParse.Utils;
using BD.Standard.YCWH.ProgramUploadERP.Utils;
using Newtonsoft.Json.Linq;
using System;
using System.Data;

namespace BD.Standard.YCWH.ProgramUploadERP
{
    internal class PurchaseOrder
    {
        public PurchaseOrder()
        {
        }

        public void PostPurchaseOrder(string sql)
        {
            DBConnection Con = new DBConnection();
            DataSet orgIdsSet = Con.getDataSet(sql);
            if (orgIdsSet.Tables[0].Rows.Count == 0) return;
            foreach (DataRow dataH in orgIdsSet.Tables[0].Rows)
            {
                string reqJson = BuildJson.ERPSaveJson(orgIdsSet, dataH, "FPOOrderEntry");
                string respJson = WebApi.client.Save("PUR_PurchaseOrder", reqJson);

                int status = JObject.Parse(respJson)["Result"]["ResponseStatus"]["IsSuccess"].ToString().Equals("True") ? 1 : 0;
                Con.getDataSet($"update  YCWH_PurchaseOrder set status={status},reqJson='{reqJson}',respJson='{respJson}' where ID='{dataH["id"]}'");

            }
        }
        

    }
}